package Demo01;

import java.util.Comparator;
import java.util.Arrays;

//class student{
//    public String name;
//    public int age;
//    public int score;
//
//    public student(String name,int age,int score){
//        this.name=name;
//        this.age=age;
//        this.score=score;
//    }
//
//    @Override
//    public String toString(){
//        return "student{"+
//                "name="+name+'\''+
//                ",age="+age+
//                ",score="+score+
//                '}';
//    }
//}

class student implements Comparable<student>{
    public String name;
    public int age;
    public int score;

    public student(String name,int age,int score){
        this.name=name;
        this.age=age;
        this.score=score;
    }

    @Override
    public String toString(){
        return "student{"+
                "name="+name+'\''+
                ",age="+age+
                ",score="+score+
                '}';
    }

    @Override
    public int compareTo(student s){
        return s.age-this.age;
    }
}

class AgeComparator implements Comparator<student>{
    @Override
    public int compare(student s1,student s2){
        return s1.age-s2.age;
    }
}

class ScoreComparator implements Comparator<student>{
    @Override
    public int compare(student s1,student s2){
        return s1.score-s2.score;
    }
}

class NameComparator implements Comparator<student>{
    @Override
    public int compare(student s1,student s2){
        return s1.name.compareTo(s2.name);
    }
}

public class test {
//    public static void main(String[] args) {
//        student[] students=new student[3];
//        students[0] =new student("张三",10,15);
//        students[1] =new student("李四",20,25);
//        students[2] =new student("王五",30,35);
//        if(students[0].compareTo(students[1])>0){
//            System.out.println("students[0] > students[1]");
//        }
//        Arrays.sort(students);
//        System.out.println(Arrays.toString(students));
//    }

    public static void main(String[] args) {
        student[] students=new student[3];
        students[0] =new student("张三",10,15);
        students[1] =new student("李四",20,25);
        students[2] =new student("王五",30,35);

        AgeComparator ageComparator=new AgeComparator();

        ScoreComparator scoreComparator=new ScoreComparator();

        NameComparator nameComparator=new NameComparator();

        Arrays.sort(students);

        System.out.println(Arrays.toString(students));
    }

}





